import java.util.*;
//国赛
public class Main {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int t=in.nextInt();
        while(t-->0){
            long res=0;
            int n=in.nextInt();
            int k=in.nextInt();
            if(n%2==0){
                if(k>=n/2){
                    res=n/2;
                    System.out.println(res);
                }else {
                    res=k+1;
                    System.out.println(res);
                }
            }else{
                if(n>k){
                    res=k+1;
                }else{
                    res=n;
                }
                System.out.println(res);
            }
        }


    }
    public static void main2(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        int k=in.nextInt();
        int[] a=new int[n];
        long sum=0;
        for(int i=0;i<n;i++){
            a[i]=in.nextInt();
            sum+=a[i];
        }
        long max=0;
        int count=0;
        for(int i=0;i<n;i++){
            long num=0;
            while(i<n&&a[i]>0){
                num+=a[i];
                i++;
            }
            max=Math.max(max,num);
        }
        System.out.println(sum+(k-1)*max);
    }
    public static void main1(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        int m=in.nextInt();
        String s=in.next();
        String t=in.next();
        int count=0;
        for(int i=0;i<n;i++){
            if(s.charAt(i)==t.charAt(i)){
                count++;
            }
        }
        if(count<m){
            int res=n-(m-count);
            System.out.println(res);
        }else{
            int res=n-(count-m);
            System.out.println(res);
        }
    }
}